/**
 * listener to upgrade
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;


/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class UpgradeListener implements ActionListener{

	/**
	 * Field YIQIAN.
	 * (value is 1000)
	 */
	private static final int YIQIAN = 1000;
	
	/**
	 * Field WU.
	 * (value is 5)
	 */
	private static final int WU = 5;

	/**
	 * Method toString.
	
	 * @return String */
	@Override
	public String toString() {
		return "UpgradeListener []";
	}

	/**
	 * Method actionPerformed.
	 * @param e ActionEvent
	
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
	@Override
	public void actionPerformed(ActionEvent e) {

		if (PlayerInfo.getCurrentSolarSystem().getTechLevel() > WU) {
			JOptionPane.showMessageDialog(ConfigurationScreen.MyFrame, 
					"The Tech Level has already achieved the max!");
			return;
		}

		if (PlayerInfo.getMoney() < YIQIAN) {
			JOptionPane.showMessageDialog( ConfigurationScreen.MyFrame, 
					"You don't have enough money to upgrade");
			return;
		}

		PlayerInfo.CurrentPlanet.getSolarSystem().setTechLevel(
				PlayerInfo.CurrentPlanet.getSolarSystem().getTechLevel() + 1);
		MarketPlaceScreen.TechLevel.setText("" + 
				PlayerInfo.getCurrentPlanet().getSolarSystem().getTechLevel());
		PlayerInfo.setMoney(PlayerInfo.getMoney() - YIQIAN);
		MarketPlaceScreen.Money.setText("" + PlayerInfo.getMoney());

	}

}
